package com.stackandqueue;

import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public class RemoveAllAdjacentDuplicatesInString0204_1047 {
    public String removeDuplicates(String s) {
        Stack<Character> que = new Stack<>();

        for (char c : s.toCharArray()) {
            if(que.isEmpty() || que.peek() != c){
                que.push(c);
            }else {
                que.pop();
            }
        }
        StringBuilder res = new StringBuilder();
        while (!que.isEmpty()){
            res.append(que.pop());
        }
        return new String(res.reverse());
    }
}
